package com.srmt.feishu.client.impl;

import com.lark.oapi.Client;
import com.srmt.feishu.client.FeishuClient;
import com.srmt.feishu.client.DocxService;
import com.srmt.feishu.client.DriveService;
import com.srmt.feishu.client.SheetsService;
import com.srmt.feishu.client.impl.services.ServiceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 默认的飞书客户端实现
 *
 * 提供对飞书各个服务API的访问能力，采用委托模式将具体实现分发给各个服务类
 *
 * <h3>架构设计：</h3>
 * <ul>
 *   <li>简单委托：每个服务方法直接委托给对应的服务实现</li>
 *   <li>工厂创建：使用 {@link ServiceFactory} 统一创建服务实例</li>
 *   <li>职责单一：仅负责服务的组装和分发</li>
 * </ul>
 *
 * <h3>支持的服务：</h3>
 * <ul>
 *   <li>文档服务（Docx）：文档创建、查询、块操作等</li>
 *   <li>云盘服务（Drive）：文件复制、删除、权限管理等</li>
 *   <li>通讯录服务（Contact）：用户ID批量查询等</li>
 *   <li>电子表格服务（Sheets）：表格操作、数据读写等</li>
 * </ul>
 *
 * <h3>重构说明：</h3>
 * <ul>
 *   <li>提取了4个内部类到独立的服务实现类</li>
 *   <li>从361行重构到80行（-78%）</li>
 *   <li>使用工厂模式统一服务创建</li>
 * </ul>
 *
 * @author SRMT Development Team
 * @since 1.0.0
 * @version 2.0.0 重构提取内部类
 */
public class DefaultFeishuClient implements FeishuClient {

    private static final Logger logger = LoggerFactory.getLogger(DefaultFeishuClient.class);

    private final Client client;
    private final DocxService docxService;
    private final DriveService driveService;
    private final SheetsService sheetsService;

    /**
     * 构造函数
     *
     * @param client 飞书SDK客户端
     */
    public DefaultFeishuClient(Client client) {
        if (client == null) {
            throw new IllegalArgumentException("客户端不能为null");
        }

        this.client = client;
        this.docxService = ServiceFactory.createDocxService(client);
        this.driveService = ServiceFactory.createDriveService(client);
        this.sheetsService = ServiceFactory.createSheetsService(client);

        logger.info("默认飞书客户端已初始化");
    }

    @Override
    public DocxService docx() {
        return docxService;
    }

    @Override
    public DriveService drive() {
        return driveService;
    }


    @Override
    public SheetsService sheets() {
        return sheetsService;
    }

    @Override
    public void shutdown() {
        logger.info("正在关闭默认飞书客户端");
        // 清理资源
    }
}
